package java_zuoye_2;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;


public class homework_8 {
	public static void main(String[] arg) {
		int index;
		System.out.println("========随机点名器======");
		ArrayList<Students> students = new ArrayList<>();
		//存储所有同学姓名
		addstudentName(students);
		//打印同学姓名
		printstudentName( students) ;
		//随机选择同学
		index=randomStudetnNames(students) ;
		System.out.print("是" + (students.get(index)).id + "号同学" + students.get(index).name);
	}

	private static int randomStudetnNames(ArrayList<Students> students) {
		// TODO Auto-generated method stub
		Random rand = new Random();
		int index = rand.nextInt(students.size());
		return index;
	}

	private static void printstudentName(ArrayList<Students> students) {
		// TODO Auto-generated method stub
		for(Students student : students) {
			 System.out.println("学生ID：" + student.id);
	         System.out.println("学生姓名：" + student.name);
	         System.out.println("学生年龄：" + student.age);
	         System.out.println();
		}
	}

	private static void addstudentName(ArrayList<Students> students) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int length;
		Students tempstudent = new Students();
		System.out.println("请输入要存同学的个数:");
		length = sc.nextInt();
		for(int i = 0; i < length; i++) {
			System.out.println("请输入学生id");
			tempstudent.id = sc.nextInt();
			System.out.println("请输入学生姓名");
			tempstudent.name = sc.next();
			System.out.println("请输入学生年龄");
			tempstudent.age = sc.nextInt();
			students.add(i, tempstudent);
		}
	}
}
